home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Window Info / WINEXE.TXT < prev    next >
Encoding:
Text File  |  2000-05-25  |  22.3 KB  |  529 lines

  1.  
  2. Executable-File Header Format (3.1)
  3.  
  4. An executable (.EXE) file for the Windows operating system 
  5. contains a combination of code and data or a combination of 
  6. code, data, and resources. The executable file also contains 
  7. two headers: an MS-DOS header and a Windows header. The next 
  8. two sections describe these headers; the third section 
  9. describes the code and data contained in a Windows executable 
  10. file. 
  11.  
  12. MS-DOS Header
  13.  
  14. The MS-DOS (old-style) executable-file header contains four 
  15. distinct parts: a collection of header information (such as 
  16. the signature word, the file size, and so on), a reserved 
  17. section, a pointer to a Windows header (if one exists), and a 
  18. stub program. The following illustration shows the MS-DOS 
  19. executable-file header: 
  20. If the word value at offset 18h is 40h or greater, the word 
  21. value at 3Ch is typically an offset to a Windows header. 
  22. Applications must verify this for each executable-file header 
  23. being tested, because a few applications have a different 
  24. header style. 
  25. MS-DOS uses the stub program to display a message if Windows 
  26. has not been loaded when the user attempts to run a program. 
  27.  
  28. Windows Header
  29.  
  30. The Windows (new-style) executable-file header contains 
  31. information that the loader requires for segmented executable 
  32. files. This information includes the linker version number, 
  33. data specified by the linker, data specified by the resource 
  34. compiler, tables of segment data, tables of resource data, 
  35. and so on. The following illustration shows the Windows 
  36. executable-file header: 
  37. The following sections describe the entries in the Windows 
  38. executable-file header. 
  39.  
  40. Information Block
  41.  
  42. The information block in the Windows header contains the 
  43. linker version number, the lengths of various tables that 
  44. further describe the executable file, the offsets from the 
  45. beginning of the header to the beginning of these tables, the 
  46. heap and stack sizes, and so on. The following list 
  47. summarizes the contents of the header information block (the 
  48. locations are relative to the beginning of the block): 
  49.  
  50. Location Description
  51. 00h      Specifies the signature word. The low byte contains 
  52.          "N" (4Eh) and the high byte contains "E" (45h). 
  53. 02h      Specifies the linker version number. 
  54. 03h      Specifies the linker revision number. 
  55. 04h      Specifies the offset to the entry table (relative to 
  56.          the beginning of the header). 
  57. 06h      Specifies the length of the entry table, in bytes. 
  58. 08h      Reserved. 
  59. 0Ch      Specifies flags that describe the contents of the 
  60.          executable file. This value can be one or more of the 
  61.          following bits: 
  62.  
  63.          Bit Meaning
  64.          0   The linker sets this bit if the executable-file 
  65.              format is SINGLEDATA. An executable file with 
  66.              this format contains one data segment. This bit 
  67.              is set if the file is a dynamic-link library 
  68.              (DLL). 
  69.          1   The linker sets this bit if the executable-file 
  70.              format is MULTIPLEDATA. An executable file with 
  71.              this format contains multiple data segments. This 
  72.              bit is set if the file is a Windows application. 
  73.              If neither bit 0 nor bit 1 is set, the 
  74.              executable-file format is NOAUTODATA. An 
  75.              executable file with this format does not contain 
  76.              an automatic data segment. 
  77.          2   Reserved. 
  78.          3   Reserved. 
  79.          8   Reserved. 
  80.          9   Reserved. 
  81.          11  If this bit is set, the first segment in the 
  82.              executable file contains code that loads the 
  83.              application. 
  84.          13  If this bit is set, the linker detects errors at 
  85.              link time but still creates an executable file. 
  86.          14  Reserved. 
  87.          15  If this bit is set, the executable file is a 
  88.              library module. 
  89.              If bit 15 is set, the CS:IP registers point to an 
  90.              initialization procedure called with the value in 
  91.              the AX register equal to the module handle. The 
  92.              initialization procedure must execute a far 
  93.              return to the caller. If the procedure is 
  94.              successful, the value in AX is nonzero. 
  95.              Otherwise, the value in AX is zero. 
  96.              The value in the DS register is set to the 
  97.              library's data segment if SINGLEDATA is set. 
  98.              Otherwise, DS is set to the data segment of the 
  99.              application that loads the library. 
  100. 0Eh      Specifies the automatic data segment number. (0Eh is 
  101.          zero if the SINGLEDATA and MULTIPLEDATA bits are 
  102.          cleared.) 
  103. 10h      Specifies the initial size, in bytes, of the local 
  104.          heap. This value is zero if there is no local 
  105.          allocation. 
  106. 12h      Specifies the initial size, in bytes, of the stack. 
  107.          This value is zero if the SS register value does not 
  108.          equal the DS register value. 
  109. 14h      Specifies the segment:offset value of CS:IP. 
  110. 18h      Specifies the segment:offset value of SS:SP. 
  111.          The value specified in SS is an index to the module's 
  112.          segment table. The first entry in the segment table 
  113.          corresponds to segment number 1. 
  114.          If SS addresses the automatic data segment and SP is 
  115.          zero, SP is set to the address obtained by adding the 
  116.          size of the automatic data segment to the size of the 
  117.          stack. 
  118. 1Ch      Specifies the number of entries in the segment table. 
  119. 1Eh      Specifies the number of entries in the 
  120.          module-reference table. 
  121. 20h      Specifies the number of bytes in the nonresident-name 
  122.          table. 
  123. 22h      Specifies a relative offset from the beginning of the 
  124.          Windows header to the beginning of the segment table. 
  125. 24h      Specifies a relative offset from the beginning of the 
  126.          Windows header to the beginning of the resource 
  127.          table. 
  128. 26h      Specifies a relative offset from the beginning of the 
  129.          Windows header to the beginning of the resident-name 
  130.          table. 
  131. 28h      Specifies a relative offset from the beginning of the 
  132.          Windows header to the beginning of the 
  133.          module-reference table. 
  134. 2Ah      Specifies a relative offset from the beginning of the 
  135.          Windows header to the beginning of the imported-name 
  136.          table. 
  137. 2Ch      Specifies a relative offset from the beginning of the 
  138.          file to the beginning of the nonresident-name table. 
  139. 30h      Specifies the number of movable entry points. 
  140. 32h      Specifies a shift count that is used to align the 
  141.          logical sector. This count is log2 of the segment 
  142.          sector size. It is typically 4, although the default 
  143.          count is 9. (This value corresponds to the /alignment
  144.          [/a] linker switch. When the linker command line 
  145.          contains /a:16, the shift count is 4. When the linker 
  146.          command line contains /a:512, the shift count is 9.) 
  147. 34h      Specifies the number of resource segments. 
  148. 36h      Specifies the target operating system, depending on 
  149.          which bits are set: 
  150.  
  151.          Bit Meaning
  152.  
  153.          0   Operating system format is unknown. 
  154.          1   Reserved. 
  155.          2   Operating system is Microsoft Windows. 
  156.          3   Reserved. 
  157.          4   Reserved. 
  158. 37h      Specifies additional information about the executable 
  159.          file. It can be one or more of the following values: 
  160.  
  161.          Bit Meaning
  162.  
  163.          1   If this bit is set, the executable file contains 
  164.              a Windows 2.x application that runs in version 3.x
  165.               protected mode. 
  166.          2   If this bit is set, the executable file contains 
  167.              a Windows 2.x application that supports 
  168.              proportional fonts. 
  169.          3   If this bit is set, the executable file contains 
  170.              a fast-load area. 
  171. 38h      Specifies the offset, in sectors, to the beginning of 
  172.          the fast-load area. (Only Windows uses this value.) 
  173. 3Ah      Specifies the length, in sectors, of the fast-load 
  174.          area. (Only Windows uses this value.) 
  175. 3Ch      Reserved. 
  176. 3Eh      Specifies the expected version number for Windows. 
  177.          (Only Windows uses this value.) 
  178.  
  179. Segment Table
  180.  
  181. The segment table contains information that describes each 
  182. segment in an executable file. This information includes the 
  183. segment length, segment type, and segment-relocation data. 
  184. The following list summarizes the values found in the segment 
  185. table (the locations are relative to the beginning of each 
  186. entry): 
  187.  
  188. Location Description
  189.  
  190. 00h      Specifies the offset, in sectors, to the segment data 
  191.          (relative to the beginning of the file). A value of 
  192.          zero means no data exists. 
  193. 02h      Specifies the length, in bytes, of the segment, in 
  194.          the file. A value of zero indicates that the segment 
  195.          length is 64K, unless the selector offset is also 
  196.          zero. 
  197. 04h      Specifies flags that describe the contents of the 
  198.          executable file. This value can be one or more of the 
  199.          following: 
  200.  
  201.          Bit Meaning
  202.  
  203.          0   If this bit is set, the segment is a data 
  204.              segment. Otherwise, the segment is a code 
  205.              segment. 
  206.          1   If this bit is set, the loader has allocated 
  207.              memory for the segment. 
  208.          2   If this bit is set, the segment is loaded. 
  209.          3   Reserved. 
  210.          4   If this bit is set, the segment type is MOVABLE.
  211.              Otherwise, the segment type is FIXED. 
  212.          5   If this bit is set, the segment type is PURE or 
  213.              SHAREABLE. Otherwise, the segment type is IMPURE
  214.              or NONSHAREABLE.
  215.          6   If this bit is set, the segment type is PRELOAD.
  216.              Otherwise, the segment type is LOADONCALL.
  217.          7   If this bit is set and the segment is a code 
  218.              segment, the segment type is EXECUTEONLY. If this 
  219.              bit is set and the segment is a data segment, the 
  220.              segment type is READONLY. 
  221.          8   If this bit is set, the segment contains 
  222.              relocation data. 
  223.          9   Reserved. 
  224.          10  Reserved. 
  225.          11  Reserved. 
  226.          12  If this bit is set, the segment is discardable. 
  227.          13  Reserved. 
  228.          14  Reserved. 
  229.          15  Reserved. 
  230. 06h      Specifies the minimum allocation size of the segment, 
  231.          in bytes. A value of zero indicates that the minimum 
  232.          allocation size is 64K. 
  233.  
  234. Resource Table
  235.  
  236. The resource table describes and identifies the location of 
  237. each resource in the executable file. The table has the 
  238. following form: 
  239. WORD     rscAlignShift;
  240. TYPEINFO rscTypes[];
  241. WORD     rscEndTypes;
  242. BYTE     rscResourceNames[];
  243. BYTE     rscEndNames;
  244. Following are the members in the resource table: 
  245. rscAlignShift    Specifies the alignment shift count for 
  246.                  resource data. When the shift count is used 
  247.                  as an exponent of 2, the resulting value 
  248.                  specifies the factor, in bytes, for computing 
  249.                  the location of a resource in the executable 
  250.                  file. 
  251. rscTypes         Specifies an array of TYPEINFO structures 
  252.                  containing information about resource types. 
  253.                  There must be one TYPEINFO structure for each 
  254.                  type of resource in the executable file. 
  255. rscEndTypes      Specifies the end of the resource type 
  256.                  definitions. This member must be zero. 
  257. rscResourceNames Specifies the names (if any) associated with 
  258.                  the resources in this table. Each name is 
  259.                  stored as consecutive bytes; the first byte 
  260.                  specifies the number of characters in the 
  261.                  name. 
  262. rscEndNames      Specifies the end of the resource names and 
  263.                  the end of the resource table. This member 
  264.                  must be zero. 
  265.  
  266. Type Information
  267.  
  268. The TYPEINFO structure has the following form: 
  269. typedef struct _TYPEINFO {
  270.     WORD        rtTypeID;
  271.     WORD        rtResourceCount;
  272.     DWORD       rtReserved;
  273.     NAMEINFO    rtNameInfo[];
  274. } TYPEINFO;
  275. Following are the members in the TYPEINFO structure: 
  276. rtTypeID       Specifies the type identifier of the resource. 
  277.                This integer value is either a resource-type 
  278.                value or an offset to a resource-type name. If 
  279.                the high bit in this member is set (0x8000), 
  280.                the value is one of the following resource-type 
  281.                values: 
  282.  
  283.                Value            Resource type
  284.  
  285.                RT_ACCELERATOR   Accelerator table 
  286.                RT_BITMAP        Bitmap 
  287.                RT_CURSOR        Cursor 
  288.                RT_DIALOG        Dialog box 
  289.                RT_FONT          Font component 
  290.                RT_FONTDIR       Font directory 
  291.                RT_GROUP_CURSOR  Cursor directory 
  292.                RT_GROUP_ICON    Icon directory 
  293.                RT_ICON          Icon 
  294.                RT_MENU          Menu 
  295.                RT_RCDATA        Resource data 
  296.                RT_STRING        String table 
  297.                If the high bit of the value in this member is 
  298.                not set, the value represents an offset, in 
  299.                bytes relative to the beginning of the resource 
  300.                table, to a name in the rscResourceNames
  301.                member. 
  302. rtResourceCount    Specifies the number of resources of this 
  303.                type in the executable file. 
  304. rtReserved     Reserved. 
  305. rtNameInfo     Specifies an array of    NAMEINFO structures 
  306.                containing information about individual 
  307.                resources. The rtResourceCount member specifies 
  308.                the number of structures in the array. 
  309.  
  310. Name Information
  311.  
  312. The NAMEINFO structure has the following form: 
  313. typedef struct _NAMEINFO {
  314.     WORD rnOffset;
  315.     WORD rnLength;
  316.     WORD rnFlags;
  317.     WORD rnID;
  318.     WORD rnHandle;
  319.     WORD rnUsage;
  320. } NAMEINFO;
  321. Following are the members in the NAMEINFO structure: 
  322. rnOffset Specifies an offset to the contents of the resource 
  323.          data (relative to the beginning of the file). The 
  324.          offset is in terms of alignment units specified by 
  325.          the rscAlignShift member at the beginning of the 
  326.          resource table. 
  327. rnLength Specifies the resource length, in bytes. 
  328. rnFlags  Specifies whether the resource is fixed, preloaded, 
  329.          or shareable. This member can be one or more of the 
  330.          following values: 
  331.  
  332.          Value  Meaning
  333.  
  334.          0x0010 Resource is movable (MOVEABLE). Otherwise, it 
  335.                 is fixed. 
  336.          0x0020 Resource can be shared (PURE). 
  337.          0x0040 Resource is preloaded (PRELOAD). Otherwise, it 
  338.                 is loaded on demand. 
  339. rnID     Specifies or points to the resource identifier. If 
  340.          the identifier is an integer, the high bit is set 
  341.          (8000h). Otherwise, it is an offset to a resource 
  342.          string, relative to the beginning of the resource 
  343.          table. 
  344. rnHandle Reserved. 
  345. rnUsage  Reserved. 
  346.  
  347. Resident-Name Table
  348.  
  349. The resident-name table contains strings that identify 
  350. exported functions in the executable file. As the name 
  351. implies, these strings are resident in system memory and are 
  352. never discarded. The resident-name strings are case-sensitive 
  353. and are not null-terminated. The following list summarizes 
  354. the values found in the resident-name table (the locations 
  355. are relative to the beginning of each entry): 
  356.  
  357. Location Description
  358.  
  359. 00h      Specifies the length of a string. If there are no 
  360.          more strings in the table, this value is zero. 
  361. 01h - xxhSpecifies the resident-name text. This string is 
  362.          case-sensitive and is not null-terminated. 
  363. xxh + 01hSpecifies an ordinal number that identifies the 
  364.          string. This number is an index into the entry table. 
  365. The first string in the resident-name table is the module 
  366. name. 
  367.  
  368. Module-Reference Table
  369.  
  370. The module-reference table contains offsets for module names 
  371. stored in the imported-name table. Each entry in this table 
  372. is 2 bytes long. 
  373.  
  374. Imported-Name Table
  375.  
  376. The imported-name table contains the names of modules that 
  377. the executable file imports. Each entry contains two parts: a 
  378. single byte that specifies the length of the string and the 
  379. string itself. The strings in this table are not 
  380. null-terminated. 
  381.  
  382. Entry Table
  383.  
  384. The entry table contains bundles of entry points from the 
  385. executable file (the linker generates each bundle). The 
  386. numbering system for these ordinal values is 1-based--that 
  387. is, the ordinal value corresponding to the first entry point 
  388. is 1. 
  389. The linker generates the densest possible bundles under the 
  390. restriction that it cannot reorder the entry points. This 
  391. restriction is necessary because other executable files may 
  392. refer to entry points within a given bundle by their ordinal 
  393. values. 
  394. The entry-table data is organized by bundle, each of which 
  395. begins with a 2-byte header. The first byte of the header 
  396. specifies the number of entries in the bundle (a value of 00h 
  397. designates the end of the table). The second byte specifies 
  398. whether the corresponding segment is movable or fixed. If the 
  399. value in this byte is 0FFh, the segment is movable. If the 
  400. value in this byte is 0FEh, the entry does not refer to a 
  401. segment but refers, instead, to a constant defined within the 
  402. module. If the value in this byte is neither 0FFh nor 0FEh, 
  403. it is a segment index. 
  404.  
  405. For movable segments, each entry consists of 6 bytes and has 
  406. the following form: 
  407.  
  408. Location Description
  409.  
  410. 00h      Specifies a byte value. This value can be a 
  411.          combination of the following bits: 
  412.  
  413.          Bit(s)    Meaning
  414.  
  415.          0     If this bit is set, the entry is exported. 
  416.          1     If this bit is set, the segment uses a global 
  417.                (shared) data segment. 
  418.          3-7   If the executable file contains code that 
  419.                performs ring transitions, these bits specify 
  420.                the number of words that compose the stack. At 
  421.                the time of the ring transition, these words 
  422.                must be copied from one ring to the other. 
  423. 01h      Specifies an int 3fh instruction. 
  424. 03h      Specifies the segment number. 
  425. 04h      Specifies the segment offset. 
  426.  
  427. For fixed segments, each entry consists of 3 bytes and has the 
  428. following form: 
  429.  
  430. Location Description
  431.  
  432. 00h      Specifies a byte value. This value can be a 
  433.          combination of the following bits: 
  434.  
  435.          Bit(s)    Meaning
  436.  
  437.          0     If this bit is set, the entry is exported. 
  438.          1     If this bit is set, the entry uses a global 
  439.                (shared) data segment. (This may be set only 
  440.                for SINGLEDATA library modules.) 
  441.          3-7   If the executable file contains code that 
  442.                performs ring transitions, these bits specify 
  443.                the number of words that compose the stack. At 
  444.                the time of the ring transition, these words 
  445.                must be copied from one ring to the other. 
  446. 01h      Specifies an offset. 
  447.  
  448. Nonresident-Name Table
  449.  
  450. The nonresident-name table contains strings that identify 
  451. exported functions in the executable file. As the name 
  452. implies, these strings are not always resident in system 
  453. memory and are discardable. The nonresident-name strings are 
  454. case-sensitive; they are not null-terminated. The following 
  455. list summarizes the values found in the nonresident-name 
  456. table (the specified locations are relative to the beginning 
  457. of each entry): 
  458.  
  459. Location Description
  460.  
  461. 00h      Specifies the length, in bytes, of a string. If this 
  462.          byte is 00h, there are no more strings in the table. 
  463. 01h - xxhSpecifies the nonresident-name text. This string is 
  464.          case-sensitive and is not null-terminated. 
  465. xx + 01h Specifies an ordinal number that is an index to the 
  466.          entry table. 
  467. The first name that appears in the nonresident-name table is 
  468. the module description string (which was specified in the 
  469. module-definition file). 
  470.  
  471. Code Segments and Relocation Data
  472.  
  473. Code and data segments follow the Windows header. Some of the 
  474. code segments may contain calls to functions in other 
  475. segments and may, therefore, require relocation data to 
  476. resolve those references. This relocation data is stored in a 
  477. relocation table that appears immediately after the code or 
  478. data in the segment. The first 2 bytes in this table specify 
  479. the number of relocation items the table contains. A 
  480. relocation item is a collection of bytes specifying the 
  481. following information: 
  482.   Address type (segment only, offset only, segment and 
  483.   offset) 
  484.   Relocation type (internal reference, imported ordinal, 
  485.   imported name) 
  486.   Segment number or ordinal identifier (for internal 
  487.   references) 
  488.   Reference-table index or function ordinal number (for 
  489.   imported ordinals) 
  490.   Reference-table index or name-table offset (for imported 
  491.   names) 
  492. Each relocation item contains 8 bytes of data, the first byte 
  493. of which specifies one of the following relocation-address 
  494. types: 
  495.  
  496. Value  Meaning
  497.  
  498. 0      Low byte at the specified offset 
  499. 2      16-bit selector 
  500. 3      32-bit pointer 
  501. 5      16-bit offset 
  502. 11     48-bit pointer 
  503. 13     32-bit offset 
  504. The second byte specifies one of the following relocation 
  505. types: 
  506.  
  507. Value  Meaning
  508.  
  509. 0      Internal reference 
  510. 1      Imported ordinal 
  511. 2      Imported name 
  512. 3      OSFIXUP
  513. The third and fourth bytes specify the offset of the 
  514. relocation item within the segment. 
  515. If the relocation type is imported ordinal, the fifth and 
  516. sixth bytes specify an index to a module's reference table and 
  517. the seventh and eighth bytes specify a function ordinal value. 
  518. If the relocation type is imported name, the fifth and sixth 
  519. bytes specify an index to a module's reference table and the 
  520. seventh and eighth bytes specify an offset to an imported-name 
  521. table. 
  522. If the relocation type is internal reference and the segment 
  523. is fixed, the fifth byte specifies the segment number, the 
  524. sixth byte is zero, and the seventh and eighth bytes specify 
  525. an offset to the segment. If the relocation type is internal 
  526. reference and the segment is movable, the fifth byte specifies 
  527. 0FFh, the sixth byte is zero; and the seventh and eighth bytes 
  528. specify an ordinal value found in the segment's entry table. 
  529.